import { czjxqAdd, czjxqDel, czjxqEdit, czjxqList } from '../services/api';

export default {
    namespace: 'town',
    state: {
        town: {},
    },
    effects: {
        * fetch({ payload }, { call, put }) {
            const response = yield call(czjxqList, payload);
            yield put({
                type: 'save',
                payload: response.data,
            });
        },
        * edit({ payload, callback }, { call }) {
            const response = yield call(czjxqEdit, payload);
            callback(response);
        },
        * add({ payload, callback }, { call }) {
            const response = yield call(czjxqAdd, payload);
            callback(response);
        },
        * del({ payload, callback }, { call }) {
            const response = yield call(czjxqDel, payload);
            callback(response);
        },

    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                town: action.payload,
            };
        },
    },
};

